home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gnulib / libsrc98.zoo / dup.c < prev    next >
C/C++ Source or Header  |  1993-03-01  |  878b  |  45 lines

  1. /* from Dale Schumacher's dLibs library */
  2.  
  3. /* these will have to be adjusted at some time ++jrb */
  4. /* use these with caution, TOS 1.4 still has double re-direction bug! */
  5.  
  6. #include <stddef.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #include <osbind.h>
  10. #include <errno.h>
  11. #include "lib.h"
  12.  
  13. int dup(handle)
  14.     int handle;
  15. {
  16.     register int rv;
  17.  
  18.     rv = Fdup(handle);
  19.     if(( rv < (__SMALLEST_VALID_HANDLE)) ||
  20.        (__OPEN_INDEX(rv) >= __NHANDLES) ) {
  21.         errno = -rv; rv = -1;
  22.     } else {
  23.         __open_stat[__OPEN_INDEX(rv)] =
  24.         __open_stat[__OPEN_INDEX(handle)];
  25.     }
  26.  
  27.     return(rv);
  28. }
  29.  
  30. int dup2(handle1, handle2)
  31.     int handle1, handle2;
  32. {
  33.     int rv;
  34.  
  35.     close(handle2);
  36.     rv = Fforce(handle2, handle1);
  37.     if ((rv < 0) ||
  38.         (__OPEN_INDEX(handle2) >= __NHANDLES))
  39.         errno = -rv;
  40.     else
  41.         __open_stat[__OPEN_INDEX(handle2)] =
  42.         __open_stat[__OPEN_INDEX(handle1)];
  43.     return (rv < 0) ? -1 : handle2;
  44. }
  45.